﻿<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <TransformXMLPath>3rdParties\TransformXML</TransformXMLPath>
    <VisualStudioDir>C:\Program Files (x86)\Microsoft Visual Studio 10.0\</VisualStudioDir>
    <CodeMetrics>$(VisualStudioDir)Team Tools\Static Analysis Tools\FxCop\Metrics.exe</CodeMetrics>
  </PropertyGroup>  

  <Target Name="TestReports">
    <Exec Command="3rdParties\trx2html\trx2html TestResults\UnitTests.trx"></Exec>
    <CallTarget Targets="ReflectorReport"/>
  </Target>

  <Target Name="ReflectorReport">
    <Exec command="$(ReflectorLocation)\Reflector.exe /Run:Reflector.CodeMetrics /Assembly:Crap4Net\bin\Debug\Crap4Net.dll /OutputPath:TestResults/ReflectorReport.xml"></Exec>
  </Target>

  <Target Name="DeletePreviousResult">
    <RemoveDir Directories="Report" ContinueOnError="true"/>
    <MakeDir Directories="Report" ContinueOnError="true"/>
  </Target>

  <UsingTask TaskName="NBehave.MSBuild.NBehaveTask" AssemblyFile="3rdParties\NBehave\v4.0\NBehave.MSBuild.dll"/>

  <Target Name="NBehave" DependsOnTargets="DeletePreviousResult">
    <NBehaveTask
      DryRun="true"
      FailBuild="false"
      XmlOutputFile="Report\tempAcceptanceResults.xml"
      TextOutputFile="Report\AcceptanceResults.txt"
      TestAssemblies="Crap4Net.AcceptanceTests\bin\Debug\Crap4Net.AcceptanceTests.dll"
      ScenarioFiles="Crap4Net.AcceptanceTests\Features\*.feature" />
    <CallTarget Targets="NBehaveReport"></CallTarget>
  </Target>

  <Target Name="NBehaveReport" >
    <Copy SourceFiles="Report\tempAcceptanceResults.xml" DestinationFiles="Report\AcceptanceResults.xml" />
    <Exec Command="$(TransformXMLPath)\TransformXml.exe -i Report\AcceptanceResults.xml -s $(TransformXMLPath)\xsl\NBehaveResults.xsl > Report\AcceptanceResults.html" />
  </Target>
  <Import Project="3rdParties\CustomTasks\CustomTasks.tasks"/>
  
  <Target Name="CrapReport" DependsOnTargets="DeletePreviousResult">
      <Message Text="Gathering Code Metrics" />
      <ExportCodeMetrics
                CodeMetrics="$(CodeMetrics)"
                SolutionFile="Crap4Net.sln"
                OutputFile="Report\Metrics.xml"
                Configuration="Debug"/>
    <Message Text="Converting Coverage Report to xml" />
  </Target>
</Project>